import java.io.IOException;

import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPortOut;
public class OSCWB {
	public static String LOCAL_HOST = "127.0.0.1"; // dont forget to update the port too!
	public static String IP_OtherComputer="169.254.251.148";
	public static int Port = 51973;
	public static OSCPortOut out;
	public static String inputString;
	public static Object[] inputArray;
	public String dataControl="/dataControl";
	public void init() {
		try {
//			InetAddress ina = InetAddress.getByName(IP_OtherComputer);
			InetAddress ina = InetAddress.getByName(LOCAL_HOST);
			out = new OSCPortOut(ina,Port);
		} 
		
		catch (SocketException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		} 
		
		catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		}
	}
	
	public void sendMessage(String label) {

			Object[] args2 = new Object[inputArray.length];
			for (int j = 0; j < inputArray.length; j++)
			{
				args2[j] = inputArray[j];
			}
			OSCMessage msg2 = new OSCMessage(label, args2);
			try {
				out.send(msg2);
			} 
			
			catch (IOException e) {

			e.printStackTrace();
			}
//			System.out.println("OSC out");
//		}
	}
	
	public static void main(Object[] k,String label) {
		inputArray = k;
		OSCWB myOSC = new OSCWB();
		myOSC.init();
		myOSC.sendMessage(label);
	}
	public static void sendSelf(String k, String label) {
		try {
			InetAddress ina = InetAddress.getByName("127.0.0.1");
			out = new OSCPortOut(ina,Port);
		} 
		
		catch (SocketException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		} 
		
		catch (UnknownHostException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		}

		inputArray= new Object[1];
		inputArray[0] = k;
		OSCWB myOSC = new OSCWB();
		myOSC.sendMessage(label);	

	}
}
